!
! AnyDATA USB Modem CCL
! Author: James Park
!
! Copyright: 2007 BeyondTech, Inc.	All Rights Reserved.
!
! revision history:
! 07/04/13	Birth
!
@ORIGINATE
!
note "Starting AnyDATA Support CCL" 3
!
! ---- Initial modem setup ----
!
! Set serial port speed to 7200000, 8 data bits and 1 stop bit(878k)
note "Try connect 878k" 3
serreset 7200000, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
matchclr
matchstr 1 2 "OK\13\10"
write "AT\13"
matchread 30
!
! Set serial port speed to 3600000, 8 data bits and 1 stop bit(439k)
note "Try connect 439k" 3
serreset 3600000, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
matchclr
matchstr 1 2 "OK\13\10"
write "AT\13"
matchread 30
!
! Set serial port speed to 1800000, 8 data bits and 1 stop bit(219k)
note "Try connect 219k" 3
serreset 1800000, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
matchclr
matchstr 1 2 "OK\13\10"
write "AT\13"
matchread 30
!
! Set serial port speed to 921600, 8 data bits and 1 stop bit(115200 BPS; 112k)
note "Try connect 112k" 3
serreset 921600, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
matchclr
matchstr 1 2 "OK\13\10"
write "AT\13"
matchread 30
!
! Set serial port speed to 460800, 8 data bits and 1 stop bit(57600 BPS; 56k)
note "Try connect 56k" 3
serreset 460800, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
matchclr
matchstr 1 2 "OK\13\10"
write "AT\13"
matchread 30
!
! Set serial port speed to 230400, 8 data bits and 1 stop bit(28800 BPS)
note "Try connect 28800" 3
serreset 230400, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
matchclr
matchstr 1 2 "OK\13\10"
write "AT\13"
matchread 30
!
! Set serial port speed to 115200, 8 data bits and 1 stop bit(14400 BPS)
note "Try connect 14400" 3
serreset 115200, 0, 8, 1
hsreset 0 0 0 0 0 0
settries 0
matchclr
matchstr 1 2 "OK\13\10"
write "AT\13"
matchread 30
!
@LABEL 2
!
! Get the modem's attention
!
matchclr
matchstr 1 3 "OK\13\10"
matchstr 2 101 "ERROR\13\10"
write "AT\13"
matchread 30
!
inctries
iftries 3 101
!
! Reset modem on failure - try again
!
dtrclear
pause 5
dtrset
write "AT&F\13"
pause 10
flush
JUMP 2
!
@LABEL 3
!
settries 0
!
@LABEL 4
!
! Setup the modem for the following:
!   Echo off (E0)
!   Verbose result on (V1)
!   Reset to factory settings (&F)
!   Hang up on DTR on to off transition (&D2)
!   Track remote DCD (&C1)
!   Unix compatible DCD control (&C2)
!   Turn off answering (S0=0)
!
matchclr
matchstr 1 5   "OK\13\10"
matchstr 2 101 "ERROR\13\10"
!
write "ATE0V1&F&D2&C1S0=0\13"
matchread 30
!
@LABEL 5
note "The first Init succeed" 3
!
matchclr
matchstr 1 6   "OK\13\10"
matchstr 2 101 "ERROR\13\10"
!
write "ATX1\13"
matchread 30
!
@LABEL 6
note "The second init succeed" 3
!
matchclr
matchstr 1 7   "OK\13\10"
matchstr 2 101 "ERROR\13\10"
!
write "ATS0=0\13"
matchread 30
!
inctries
iftries 3 101
!
! Reset the Modem on setup failure
!
DTRClear
pause 5
DTRSet
write "AT&F\13"
pause 10
flush
JUMP 4
!
!
@LABEL 7
!
note "Connecting to Network" 3
!
write "ATD^7\13"
!
! ---- Connect -----
!
@LABEL 20
matchclr
matchstr  1 30  "CONNECT\13\10"
matchstr  2 30  "CONNECT "
matchstr  3 102 "NO DIALTONE\13\10"
matchstr  4 103 "NO CARRIER"
matchstr  5 103 "ERROR\13\10"
matchstr  6 104 "BUSY\13\10"
matchstr  7 105 "NO ANSWER\13\10"
matchstr  8 20  "CARRIER"
matchread 300
JUMP 101
!
! Set the standard connect message
!
@LABEL 30
note "Communicating at unknown rate" 3
!
!CommunicatingAt 230400
CommunicatingAt 3600000
!
! Turn on CTS handshaking
!
hsreset 0 1 0 0 0 0
pause 5
!
exit 0
!
! ---- Hang up and reset modem ----
!
@HANGUP 
@LABEL 90 
settries 0
hsreset 0 0 0 0 0 0
DTRClear
note "Hang up..." 3
!
@LABEL 91
! 
! Try to get control of the modem
! 
flush
pause 1
write "+++"
pause 1 
matchclr
matchstr 1 93 "OK\13\10"
matchread 30
!
@LABEL 93
! 
! hangup
! 
flush
matchclr
matchstr 1 99 "NO CARRIER\13\10"
matchstr 2 99 "OK\13\10"
matchstr 3 95 "ERROR\13\10"
!
write "ATH E1\13"
matchread 30
! 
! Try again to get control of the modem by toggling DTR
!
@LABEL 95
note "LABEL 95" 3
hsreset 0 0 0 0 0 0
DTRClear
Pause 2
DTRSet
flush
write "AT&F\13"
pause 10
exit 0
!
! Try the hangup sequence three times otherwise declare an error
! 
inctries
iftries 3 101
JUMP 91
!
@LABEL 99
note "succeed" 3
exit 0
!
! ---- Answer calls ----
!
@ANSWER
write "ATA\13"
pause 1
exit -6002 "Device does not support call answering."
!
! ---- Error messages ----
!
! Modem Not Responding
!
@LABEL 101
exit -6019
!
! No Dial Tone
!
@LABEL 102
exit -6020
!
! No Carrier or Error
!
@LABEL 103
exit -6021
!
! Busy
!
@LABEL 104
exit -6022
!
! No Answer
!
@LABEL 105
exit -6023
!
! User Cancellation
!
@LABEL 107
exit -6008
!